package net.zjitc.controller;

import net.zjitc.common.ResponseResult;
import net.zjitc.entity.Permission;
import net.zjitc.entity.Vo.PermissionVo;
import net.zjitc.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin
@RestController
public class PermissionContrller {
    @Autowired
    private PermissionService permissionService;
    ResponseResult result=new ResponseResult();
    @GetMapping("/rights/{type}")
    public ResponseResult findAll(@PathVariable String type){
        List<PermissionVo> permissionList=null;


        if(type.equals("list")){
            permissionList=permissionService.selectAll();
            result.setSuccess("获取权限列表成功",permissionList);
        }else if(type.equals("tree")){
            permissionList=permissionService.getTree();
            result.setSuccess("获取权限列表成功",permissionList);
        }
        return result;
//        List<Permission> permissionList= null;
//        if(type.equals("list")){
//            permissionList=permissionService.selectAll();
//        }
//        ResponseResult result=new ResponseResult();
//        result.setSuccess("获取权限列表成功",permissionList);
//        return result;
    }
    @GetMapping("menus")
    public ResponseResult getMenus(){
        List<PermissionVo> permissionList=permissionService.getMenus();
        if (permissionList!=null){
            result.setSuccess("获取菜单成功",permissionList);
        }else {
            result.setError("获取菜单失败",null);
        }
        return result;
    }
}
